package pers.zh.parking.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import butterknife.BindView;
import pers.zh.parking.R;
import pers.zh.parking.data.UserSettings;
import pers.zh.parking.di.component.DaggerAdminComponent;
import pers.zh.parking.mvp.contract.AdminContract;
import pers.zh.parking.mvp.presenter.AdminPresenter;

import static com.jess.arms.utils.Preconditions.checkNotNull;

public class AdminActivity extends BaseActivity<AdminPresenter> implements AdminContract.View {

    @BindView(R.id.tvNoticeManage)
    TextView tvNoticeManage;
    @BindView(R.id.tvLotManage)
    TextView tvLotManage;
    @BindView(R.id.ivLeft)
    ImageView ivLeft;
    @BindView(R.id.toolbar_left)
    RelativeLayout toolbarLeft;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.ivRight)
    ImageView ivRight;
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerAdminComponent //如找不到该类,请编译一下项目
                             .builder().appComponent(appComponent).view(this).build().inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_admin; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        tvNoticeManage.setOnClickListener(
                v -> launchActivity(new Intent(AdminActivity.this, NoticeManageActivity.class)));
        tvLotManage.setOnClickListener(
                v -> launchActivity(new Intent(AdminActivity.this, LotManageActivity.class)));
        ivLeft.setOnClickListener(v -> {
            UserSettings.getInstance().setLogin(false);
            UserSettings.getInstance().clear();
            finish();
        });
        tvTitle.setText("欢迎您，" + UserSettings.getInstance().getUserName());
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

}
